from flask import Blueprint,jsonify,request,abort
from flask_restful import Api,Resource
from app.models import *
eduget0 = Api()


class EduGet1(Resource):
    def get(self):
        task = EduGet.query.all()
        return jsonify({"EduGet1": list(map(con9, task))})
    def post(self):
        eduget = EduGet(
            request.json.get('time'),
            request.json.get('usewhere'),
            request.json.get('payobject'),
            request.json.get('people_get'),
            request.json.get('real_money'),
            request.json.get('none_money'),
            request.json.get('discount'),
            request.json.get('off_style'),
            request.json.get('beizhu')
        )

        db.session.add(eduget)
        db.session.commit()
        return jsonify({'eduget': con9(eduget)})
eduget0.add_resource(EduGet1, "/EduGet1/")


class EduGte2(Resource):
    def get(self, uid):
        task = EduGet.query.filter_by(id=uid).first()
        if EduGte2 is None:
            abort(404)
        return jsonify({'EduGte2': con9(task)})

    def put(self, uid):
        eduget_update = EduGet.query.get(EduGte2)
        eduget_update.time = request.json.get('time')
        eduget_update.usewhere = request.json.get('usewhere')
        eduget_update.payobject = request.json.get('payobject')
        eduget_update.people_get = request.json.get('people_get')
        eduget_update.real_money = request.json.get('real_money')
        eduget_update.none_money = request.json.get('none_money')
        eduget_update.discount = request.json.get('discount')
        eduget_update.off_style = request.json.get('off_style')
        eduget_update.beizhu = request.json.get('beizhu')
        db.session.add(eduget_update)
        db.session.commit()
        return jsonify({'eduget_update': con9(eduget_update)})
    def delete(self,uid):
        tasks =EduGet.query.get(uid)
        tasks.mark=False
        db.session.add(tasks)
        db.session.commit()
        return jsonify({'delete':con9(tasks)})



eduget0.add_resource(EduGte2, "/EduGet2/<int:uid>/")